<template>
  <div class="category-container">
    <el-card class="category-card">
      <template #header>
        <div class="card-header">
          <span>分类管理</span>
          <el-button type="primary" @click="handleAddCategory">添加分类</el-button>
        </div>
      </template>

      <el-table :data="categories" style="width: 100%">
        <el-table-column prop="name" label="分类名称" />
        <el-table-column prop="code" label="分类编码" />
        <el-table-column prop="sort" label="排序" width="100" />
        <el-table-column prop="createTime" label="创建时间" width="180" />
        <el-table-column label="操作" width="200">
          <template #default="scope">
            <el-button size="small" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button 
              size="small" 
              type="danger" 
              @click="handleDelete(scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessageBox, ElMessage } from 'element-plus'

const categories = ref([
  {
    id: 1,
    name: '技术',
    code: 'tech',
    sort: 1,
    createTime: '2024-01-20 10:00:00'
  },
  {
    id: 2,
    name: '生活',
    code: 'life',
    sort: 2,
    createTime: '2024-01-19 15:30:00'
  }
])

const handleAddCategory = () => {
  ElMessage.success('添加分类功能待实现')
}

const handleEdit = (category) => {
  ElMessage.success(`编辑分类 ${category.name} 功能待实现`)
}

const handleDelete = (category) => {
  ElMessageBox.confirm(`确定要删除分类 ${category.name} 吗？`, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    ElMessage.success(`分类 ${category.name} 已删除`)
  }).catch(() => {
    ElMessage.info('已取消删除')
  })
}
</script>

<style scoped lang="scss">
.category-container {
  padding: 20px;
}

.category-card {
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
</style> 